
const app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
     items: [
       {
        name: '男',
        checked: true
      },
      {
        name: '女',
        checked: false
      },
      {
        name: '保密',
        checked: false
      }
    ],
    info:[],
    region: ['广东省', '广州市', '海珠区'],
    customItem: '全部'
  },
  // 多行文本域
  bindTextAreaBlur: function (e) {
    console.log(e.detail.value);
    var that = this;
    that.setData({
      details: e.detail.value
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that=this;
    // if (Object.keys(options).length == 0){
    //   console.log('1313')
    // }
    if (options.id > 0) {
      that.getAddress(options.id);
      
    }

  },
  getAddress: function (id) {//修改地址
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Car/getAddress',
      data: {
        // opt: 'getAddress',
        userId: 1,
        id: id,
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data != null) {
          that.setData({
            info:res.data,
            
          })
        }
      }
    })
  },
  bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value,
      ProvId: null
    })
  },
  formSubmit: function (e) {//新增地址
    console.log(e)
    var that = this;
    var formData = e.detail.value;
    formData['userId']=wx.getStorageSync('userId');
    if (that.data.region[0] == "") {
      wx.showToast({
        title: '地区必选!',
        icon: 'loading',
        duration: 1500
      })
      return;
    }
    if (e.detail.value.Addressee.length == 0 || e.detail.value.Phone.length == 0) {
      wx.showToast({
        title: '不得为空!',
        icon: 'loading',
        duration: 1500
      })
    } else {
      wx.request({
        url: app.globalData.apiUrl + 'Car/addAddress', //接口地址
        data: formData,
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          if (res.data.status == 1) {
            wx.showToast({
              title: '提交成功!',//这里打印出登录成功
              icon: 'success',
              duration: 1000,
              success: function () {
                wx.redirectTo({
                  url: '../../address/address?isorderpage=' + that.data.isorderpage,
                })
              }
            })
          } else {
            wx.showToast({
              title: '提交失败!',
              icon: 'loading',
              duration: 1500
            })
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})